package com.dhecp.project.system.service.impl;

import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.system.domain.SysVersionItem;
import com.dhecp.project.system.mapper.SysVersionItemMapper;
import com.dhecp.project.system.service.SysVersionItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName SysVersionItemServiceImpl
 * @Description TODO
 * @Author alula
 * @Date 2020-03-12 11:18
 */
@Service
public class SysVersionItemServiceImpl implements SysVersionItemService {

    @Autowired
    private SysVersionItemMapper sysVersionItemMapper;

    @Override
    public List<SysVersionItem> queryVersionItemList(Map<String, Object> params) {
        return sysVersionItemMapper.findVersionItemList(params);
    }

    @Override
    public SysVersionItem queryVersionItemById(String guid) {
        return  sysVersionItemMapper.findVersionItemById(guid);
    }

    @Override
    public AjaxResult insertVersionItem(SysVersionItem sysVersionItem) {
        try {
            if (sysVersionItem == null) {
                return AjaxResult.error(MessageUtils.message("module.error.paramfail", sysVersionItem));
            }
            sysVersionItem.setCreateUser(ShiroUtils.getMandatorId());
            sysVersionItemMapper.insert(sysVersionItem);
            return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
        }catch (Exception e){
            return AjaxResult.error(MessageUtils.message("module.error.iserror"));
        }
    }

    @Override
    public AjaxResult updateVersionItem(SysVersionItem sysVersionItem) {
        try {
            if (sysVersionItem == null) {
                return AjaxResult.error(MessageUtils.message("module.error.paramfail", sysVersionItem));
            }
            sysVersionItem.setUpdateUser(ShiroUtils.getMandatorId());
            sysVersionItemMapper.update(sysVersionItem);
            return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
        }catch (Exception e){
            return AjaxResult.error(MessageUtils.message("module.error.iserror"));
        }
    }

    @Override
    public AjaxResult deleteVersionItem(String guid) {
        if (StringUtils.isEmpty(guid)) {
            return AjaxResult.error(MessageUtils.message("module.error.paramfail", guid));
        }
        try {
            sysVersionItemMapper.deleteVersionItemByGuid(guid);
            return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
        }catch (Exception e){
            return AjaxResult.error(MessageUtils.message("module.error.iserror"));
        }
    }
}
